<?php if (!defined('SERVER_ROOT')) {exit('No direct script access allowed');}
//header
$this->template->title = 'Đơn vị';
$this->template->display('dsp_header.php');
$v_MA_LOAI_DON_VI_filter     = $arr_filter['cbx_MA_LOAI_DON_VI_filter'];
$v_MA_DON_VI_CHU_QUAN_filter = $arr_filter['cbx_MA_DON_VI_CHU_QUAN_filter'];
?>
 <form name="frmMain" id="frmMain" action="" method="POST">
    <?php
    echo $this->hidden('controller',$this->get_controller_url());
    echo $this->hidden('hdn_item_id','0');
    echo $this->hidden('hdn_item_id_list','');

    echo $this->hidden('hdn_dsp_single_method','dsp_single_donvi');
    echo $this->hidden('hdn_dsp_all_method','dsp_all_donvi');
    echo $this->hidden('hdn_update_method','update_donvi');
    echo $this->hidden('hdn_delete_method','delete_donvi');
    $v_row = 0;
    ?>
    <div id="div_filter">
        <label>Loại đơn vị</label>
        <select id="cbx_MA_LOAI_DON_VI_filter"
                name="cbx_MA_LOAI_DON_VI_filter"
                onchange="this.form.submit();"
                >
                  <?php while ($arr = $arr_all_loaidonvi_filter->FetchRow()): ?>
                  <?php
                   $MA_LOAI_DON_VI_CBX=$arr['MA_LOAI_DON_VI'];
                   $TEN_LOAI_DON_VI_CBX=$arr['TEN_LOAI_DON_VI'];
                  ?>
                   <?php if($v_MA_LOAI_DON_VI_filter == $MA_LOAI_DON_VI_CBX):?>
                     <option value="<?php echo $MA_LOAI_DON_VI_CBX; ?>" selected="selected"><?php echo $TEN_LOAI_DON_VI_CBX; ?></option>
                  <?php else:?>
                     <option value="<?php echo $MA_LOAI_DON_VI_CBX; ?>" ><?php echo $TEN_LOAI_DON_VI_CBX; ?></option>
                  <?php endif ?>
                <?php endwhile; ?>
        </select>
        <label>ĐV chủ quản</label>
         <select id="cbx_MA_DON_VI_CHU_QUAN_filter"
                      name="cbx_MA_DON_VI_CHU_QUAN_filter"
                      onchange="this.form.submit();"
                      >
                          <?php while ($arr = $arr_all_donvichuquan_filter->FetchRow()): ?>
                          <?php
                           $MA_DON_VI_CHU_QUAN_CBX=$arr['MA_DON_VI_CHU_QUAN'];
                           $TEN_DON_VI_CHU_QUAN_CBX=$arr['TEN_DON_VI_CHU_QUAN'];
                          ?>
                           <?php if($v_MA_DON_VI_CHU_QUAN_filter == $MA_DON_VI_CHU_QUAN_CBX):?>
                             <option value="<?php echo $MA_DON_VI_CHU_QUAN_CBX; ?>" selected="selected"><?php echo $TEN_DON_VI_CHU_QUAN_CBX; ?></option>
                          <?php else:?>
                             <option value="<?php echo $MA_DON_VI_CHU_QUAN_CBX; ?>" ><?php echo $TEN_DON_VI_CHU_QUAN_CBX; ?></option>
                          <?php endif ?>
                          <?php endwhile; ?>
           </select>

        <input class = 'button' type="button" name="btn_add_donvi" value="Thêm đơn vị" onclick="row_donvi_onclick_pop_win('0')"/>
    </div>
    <table  width="100%" class="adminlist" cellspacing="0" border="1">
        <colgroup>
            <col width="20%" />
            <col width="20%" />
            <col width="19%" />
            <col width="6%" />
            <col width="8%" />
            <col width="8%" />
        </colgroup>
        <tr>
            <th>Tên đơn vị</th>
            <th>Loại đơn vị</th>
            <th>Đơn vị chủ quản</th>
            <th>Thứ tự</th>
            <th>Trạng thái</th>
            <th>Thao tác</th>
        </tr>
        <?php while ($arr = $arr_all_donvi->FetchRow()): ?>
            <?php
             $MA_DON_VI=$arr['MA_DON_VI'];
             $TEN_DON_VI=$arr['TEN_DON_VI'];
             $TEN_LOAI_DON_VI=$arr['TEN_LOAI_DON_VI'];
             $TEN_DON_VI_CHU_QUAN=$arr['TEN_DON_VI_CHU_QUAN'];
             $STT_DON_VI=$arr['STT_DON_VI'];
             $TEN_TRANG_THAI=$arr['TEN_TRANG_THAI'];
             $v_class = 'row' . ($v_row % 2);
             $v_row++;
             $v_link = SITE_ROOT . 'qlcb/tochuyenmon/dsp_all_tochuyenmon_dv/&m=' . $MA_DON_VI;
            ?>
            <tr class="<?php echo $v_class;?>">
                <td>
                    <a href="<?php echo $v_link;?>">
                            <?php echo $TEN_DON_VI;?>
                    </a>
                </td>
                <td><?php echo $TEN_LOAI_DON_VI;?></td>
                <td><?php echo $TEN_DON_VI_CHU_QUAN;?></td>
                <td style="text-align:center"><?php echo $STT_DON_VI;?></td>
                <td style="text-align:center"><?php echo $TEN_TRANG_THAI;?></td>
                <td style="text-align:center;vertical-align:middle">
                    <a href="javascript:void(0)" onclick="row_donvi_onclick_pop_win('<?php echo $MA_DON_VI;?>')">Sửa</a> |
                    <a href="javascript:void(0)" onclick="quick_delete_donvi('<?php echo $MA_DON_VI;?>')">Xoá</a>
                </td>
            </tr>
        <?php endwhile; ?>
        <?php echo $this->add_empty_rows($v_row +1, _CONST_DEFAULT_ROWS_PER_PAGE, 6); ?>
    </table>

</form>
<script>
    function row_donvi_onclick_pop_win(madonvi){
        var url = '<?php echo $this->get_controller_url();?>dsp_single_donvi/'  + madonvi
            url += '/?&madonvi=' + madonvi + '&hdn_item_id=' + madonvi + '&pop_win=1';
        showPopWin(url ,600,280, null);
    }
    function quick_delete_donvi(madonvi)
    {
        var f = document.frmMain;
        if (confirm('Bạn chắc chắn xoá đối tượng đã chọn?')){
            f.hdn_item_id.value =  madonvi;
            m = $("#controller").val() + 'delete_donvi'
            $("#frmMain").attr("action", m);
            f.submit();
        }
    }
</script>
<?php $this->template->display('dsp_footer.php');